//
//  TBRRentController.m
//  TBRentClient
//
//  Created by tonbright on 2018/4/26.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRRentController.h"

#import "TBREstimatePriceView.h"

#import "TBRBusinessRentView.h"
#import "TBRSendPlaneView.h"
#import "TBRReceptPlaneView.h"
#import "TBRCharteredView.h"

#import "TBRRentDetailController.h"
#import "TBRHomeModel.h"
@interface TBRRentController ()<MenuViewDelegate,TBREstimatePriceViewDelegate>

@property (nonatomic,strong)TBRBusinessRentView *businessRentView;
@property (nonatomic,strong)TBRSendPlaneView *sendPlaneView;
@property (nonatomic,strong)TBRReceptPlaneView *receptPlaneView;
@property (nonatomic,strong)TBRCharteredView *charteredView;

@property (nonatomic,strong)TBREstimatePriceView *estimatePriceView;//预估价格的view-----

@end

@implementation TBRRentController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
}

- (void)setupUI {
    //设置导航条
    [self ISG_NavigationBarDefaultBackButtonAndNavigationTitle:@"尊行租车"];
    MenuView *titleMenuView = [[MenuView alloc] initWithMenuViewWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44) titles:@[@"商务接送",@"接机",@"送机",@"包车"] index:self.selectedIndex];
    self.titleMenuView = titleMenuView;
    titleMenuView.delegate = self;
    [self.view addSubview:titleMenuView];
    
    //
    self.estimatePriceView = [TBREstimatePriceView estimatePriceView];
    [self.view addSubview:self.estimatePriceView];
    [self.estimatePriceView makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(73);
        make.leading.trailing.bottom.offset(0);
    }];
    self.estimatePriceView.delegate = self;
    
    
    TBRBusinessRentView *businessRentView = [[TBRBusinessRentView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.businessRentView = businessRentView;
    [self.view addSubview:businessRentView];
    
    //设置约束
    [self.businessRentView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleMenuView.bottom).offset(0);
        make.leading.trailing.offset(0);
        make.bottom.equalTo(self.estimatePriceView.top).offset(0);
    }];
    
    
    TBRSendPlaneView *sendPlaneView = [[TBRSendPlaneView alloc] initWithFrame:CGRectZero style:(UITableViewStyle)UITableViewStyleGrouped];
    self.sendPlaneView = sendPlaneView;
    [self.view addSubview:sendPlaneView];
    [self.sendPlaneView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleMenuView.bottom).offset(0);
        make.leading.trailing.offset(0);
        make.bottom.equalTo(self.estimatePriceView.top).offset(0);
    }];
    TBRReceptPlaneView *receptPlaneView = [[TBRReceptPlaneView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.receptPlaneView = receptPlaneView;
    [self.view addSubview:receptPlaneView];
    [self.receptPlaneView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleMenuView.bottom).offset(0);
        make.leading.trailing.offset(0);
        make.bottom.equalTo(self.estimatePriceView.top).offset(0);
    }];
    TBRCharteredView *charteredView = [[TBRCharteredView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.charteredView = charteredView;
    [self.view addSubview:charteredView];
    [self.charteredView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleMenuView.bottom).offset(0);
        make.leading.trailing.offset(0);
        make.bottom.equalTo(self.estimatePriceView.top).offset(0);
    }];
    [self menuView:self.titleMenuView didSelectedIndex:_selectedIndex-1];
}


#pragma mark - MenuViewDelegate
- (void)menuView:(MenuView *)menuView didSelectedIndex:(NSInteger)index {
    if (index == 0) {
        self.businessRentView.hidden = NO;
        self.receptPlaneView.hidden = YES;
        self.sendPlaneView.hidden = YES;
        self.charteredView.hidden = YES;
    } else if (index == 1) {
        self.businessRentView.hidden = YES;
        self.receptPlaneView.hidden = NO;
        self.sendPlaneView.hidden = YES;
        self.charteredView.hidden = YES;
    }
    else if (index == 2) {
        self.businessRentView.hidden = YES;
        self.receptPlaneView.hidden = YES;
        self.sendPlaneView.hidden = NO;
        self.charteredView.hidden = YES;
    }
    else if (index == 3) {
        self.businessRentView.hidden = YES;
        self.receptPlaneView.hidden = YES;
        self.sendPlaneView.hidden = YES;
        self.charteredView.hidden = NO;
    }
    self.selectedIndex = index + 1;
}

- (void)estimatePriceViewSureOrderBtnClick {
    //根据选中的index来传递数值---
    TBRRentDetailController *rentDetailC = [[TBRRentDetailController alloc] init];
    NSLog(@"%ld",_selectedIndex);
    rentDetailC.dataArray = self.businessRentView.dataArray;
    rentDetailC.remark = [HelpObject changeNull:self.businessRentView.remark];
    [self.navigationController pushViewController:rentDetailC animated:YES];
}

@end
